#!/sbin/openrc-run

description="Jitsi Gateway for SIP"

pidfile="/var/run/jigasi/jigasi.pid"
# launcher script below will work on OpenRC also
command="/usr/share/jigasi/jigasi.sh"
command_args=" --host=$JIGASI_HOST --domain=$JIGASI_HOSTNAME --subdomain=callcontrol --secret=$JIGASI_SECRET --logdir=$JIGASI_LOGDIR --configdir=/etc/jitsi --configdirname=jigasi $JIGASI_OPTS"
command_user="jigasi:jitsi"
command_background=true

depend() {
	need net
	want jabber-server
}

start_pre() {
	mkdir -m 770 -p /var/run/jigasi
	chown "${command_user}" /var/run/jigasi
	return 0
}

start() {
	ebegin "Starting ${name}"
	start-stop-daemon --start --quiet --background --chuid $command_user \
		-m --pidfile $pidfile \
		--exec /bin/bash -- -c "JAVA_SYS_PROPS=\"$JAVA_SYS_PROPS\" exec $command $command_args >> $JIGASI_LOGFILE 2>&1"
	eend $?
}
